package com.vcit.system.service.grade.impl;

import com.vcit.system.domain.grade.TClazzTermCourse;
import com.vcit.system.mapper.grade.TClazzTermCourseMapper;
import com.vcit.system.service.grade.ITClazzTermCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TClazzTermCourseServiceImpl implements ITClazzTermCourseService {
    @Autowired
    private TClazzTermCourseMapper mapper;

    @Override
    public TClazzTermCourse selectById(Long id) {
        return mapper.selectById(id);
    }

    @Override
    public List<TClazzTermCourse> selectList(TClazzTermCourse query) {
        return mapper.selectList(query);
    }

    @Override
    public int insert(TClazzTermCourse entity) {
        return mapper.insert(entity);
    }

    @Override
    public int update(TClazzTermCourse entity) {
        return mapper.update(entity);
    }

    @Override
    public int deleteById(Long id) {
        return mapper.deleteById(id);
    }

    @Override
    public int deleteByIds(Long[] ids) {
        return mapper.deleteByIds(ids);
    }

    @Override
    public int batchInsert(List<TClazzTermCourse> list) {
        return mapper.batchInsert(list);
    }

    @Override
    public List<TClazzTermCourse> selectListWithNames(TClazzTermCourse query) {
        return mapper.selectListWithNames(query);
    }

    @Override
    public TClazzTermCourse selectByIdWithNames(Long id) {
        return mapper.selectByIdWithNames(id);
    }

    @Override
    public int batchUpdate(List<TClazzTermCourse> list) {
        return mapper.batchUpdate(list);
    }

    @Override
    public int batchReplaceClazzTermCourses(List<TClazzTermCourse> list) {
        if (list == null || list.isEmpty()) return 0;
        Long clazzId = list.get(0).getClazzId();
        Long termId = list.get(0).getTermId();
        // 先删除该班级该学期下所有课程
        mapper.deleteByClazzAndTerm(clazzId, termId);
        // 再批量插入
        return mapper.batchInsert(list);
    }
} 